package com.tgky.ybzb.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import com.tgky.ybzb.entity.XdzyDmz;
import com.tgky.ybzb.service.IXdzyDmzService;
import com.tgky.ybzb.common.IdParam;
import com.tgky.ybzb.common.PageParam;
import com.tgky.ybzb.common.Result;
import com.tgky.ybzb.utils.MPUtil;

import java.util.List;

/**
 * 地面站表 前端控制器
 *
 * @author XYP
 * @since 2024-07-22
 */
@RestController
@AllArgsConstructor
@Slf4j
@Api(value = "地面站表", tags = "地面站表接口")
@RequestMapping("xdzy-dmz")
public class XdzyDmzController {

	private IXdzyDmzService xdzyDmzService;

	/**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "新增", notes = "传入xdzyDmz")
	public Result save(@RequestBody XdzyDmz xdzyDmz) {
		if(xdzyDmz == null){
			return Result.error("参数异常");
		}
		return Result.status(xdzyDmzService.save(xdzyDmz));
	}

	/**
	 * 修改 地面站表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "修改", notes = "传入xdzyDmz")
	public Result update(@RequestBody XdzyDmz xdzyDmz) {
		if(xdzyDmz == null){
			return Result.error("参数异常");
		}
		return Result.status(xdzyDmzService.updateById(xdzyDmz));
	}

	/**
	 * 删除 地面站表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "删除", notes = "传入ids")
	public Result remove(@RequestBody IdParam<Long> idParam) {
		if(idParam == null){
			return Result.error("参数异常！");
		}

		return Result.status(xdzyDmzService.removeByIds(idParam.getIds()));
	}

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "详情", notes = "传入id")
	public Result<XdzyDmz> detail(Long id) {
		if(id == null){
			return Result.error("参数异常");
		}
		XdzyDmz detail = xdzyDmzService.getById(id);
		return Result.successData(detail);
	}

	/**
	 * 查询 地面站表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "查询", notes = "传入xdzyDmz")
	public Result list(PageParam pageParam, XdzyDmz xdzyDmz) {
		List<XdzyDmz> list = xdzyDmzService.list(xdzyDmzService.getQueryWrapper(pageParam, xdzyDmz));
		return Result.successData(list);
	}

	/**
	 * 分页 地面站表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "分页", notes = "传入xdzyDmz")
	public Result<IPage> page(PageParam pageParam, XdzyDmz xdzyDmz) {
		IPage<XdzyDmz> pages = xdzyDmzService.page(
				MPUtil.getPage(pageParam),
				xdzyDmzService.getQueryWrapper(null, xdzyDmz)
		);
		return Result.successData(pages);
	}

}
